/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MainPackage;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.*;
import javax.swing.DefaultListModel;
import javax.swing.JList;

/**
 *
 * @author n.kaminski
 */
public class Sportarten {
    
    private Map<String, Double[]> Sport = new HashMap<String, Double[]>();
    
    public Sportarten(){
        InputStream stream = MainWindow.class.getResourceAsStream("/ConfigFiles/SportartenConfig.txt");            
        if(stream!=null) {
            InputStreamReader reader=new InputStreamReader(stream);
            try {
                String content = ""; 
                int x = reader.read();
                while(x != -1){
                    content += (char)x;
                    if((char)x == '\n'){
                        content = content.replace("\n", "");
                        //content = content.replace("\t", " ");
                        content = content.replace("  ", " ");
                        content = content.replace("  ", " ");
            
                        String[] f1 = content.split(" ");
                        Double[] c = new Double[6];
                        c[0] =Integer.parseInt(f1[0])*1.0;
                        String name = "";
                        for(int i = 1; i <= f1.length - 6; ++i){
                            name += f1[i]+" ";
                        }
                        for(int i = 1; i < c.length; ++i){
                            c[i] = Integer.parseInt(f1[f1.length - 6 + i]) / 15.0;
                        }
                        
                        /*System.out.print(name+": ");
                        for(int i = 1; i < c.length; ++i){
                            System.out.print(c[i]+", ");  
                        }
                        System.out.print("\n");*/
                        Sport.put(name, c);
                        content = "";
                    }
                    x = reader.read();
                }
            }
            catch(Exception ioe) {
                System.out.println("Da lauft was falsch");
            }  
        }
                
    }
    
    public void FillJList(JList liste){
        
        DefaultListModel dlm = new DefaultListModel();
        Set<String> keys = Sport.keySet();
        String[] s = keys.toArray(new String[0]);
        
        Arrays.sort(s);
        int i = 0;
        for(String k : s){
            dlm.add( i, k);
            i++;
        }
        
        liste.setModel(dlm);
    }
    
    public double getKCAL(String name, User user){
        UserGewicht ug = user.getUsergewicht();
        if(!Sport.containsKey(name)){
            return 0;
        }
        double gew = ug.getGewicht(ug.Count()-1);
        if(gew < 65){
            return Sport.get(name)[1];
        }else if(gew < 75){
            return Sport.get(name)[2];
        }else if(gew < 85){
            return Sport.get(name)[3];
        }else if(gew < 95){
            return Sport.get(name)[4];
        }else{
            return Sport.get(name)[5];
        }
        
    }
}
